using System;
using System.Collections.Generic;

namespace ECCIT.Data
{
	/// <summary>
	///		The Field class which inherited from BaseField is used to the business class  
	/// </summary>
	[Serializable]
	public class Field : IField
	{
		private Type _type;
		private string _propertyName;   // the property name of the entity class binded to the field
		private IColumn _column;
        private ClassFieldCreator _classFieldCreator;

		public Type Type
		{
			get{ return _type; }
			set{ _type = value; }
		}

		public string PropertyName
		{
			get{ return _propertyName; }
			set{ _propertyName = value; }
		}

		public IColumn Column
		{
			get{ return _column; }
			set{ _column = value; }
		}

        public ClassFieldCreator ClassFieldCreator
        {
            get { return _classFieldCreator; }
            set { _classFieldCreator = value; }
        }

        public Field(Type type, string propertyName, IColumn column) : this(type, propertyName, column, null) { }

        public Field(Type type, string propertyName, IColumn column, ClassFieldCreator fieldCreator)
        {
            _type = type;
            _propertyName = propertyName;
            _column = column;
            _classFieldCreator = fieldCreator;
        }

        /// <summary>
        ///     Indicates whether Field can be inserted to DB.
        /// </summary>
        [AttributeUsage(AttributeTargets.Property, Inherited = false)]
        [Serializable]
        public class InsertableAttribute : Attribute
        {
            public InsertableAttribute() { }
        }

        /// <summary>
        ///     Indicates whether Field can be selected from DB.
        /// </summary>
        [AttributeUsage(AttributeTargets.Property, Inherited = false)]
        [Serializable]
        public class SelectableAttribute : Attribute
        {
            public SelectableAttribute() { }
        }

        /// <summary>
        ///     Indicates whether Field can be updated to DB.
        /// </summary>
        [AttributeUsage(AttributeTargets.Property, Inherited = false)]
        [Serializable]
        public class UpdatableAttribute : Attribute
        {
            public UpdatableAttribute() { }
        }
	}
}
